﻿using System;
using System.Collections.Generic;
using DomainModel.Domain.Bases;
using DomainModel.Utils;

namespace DomainModel.Domain.Model
{
    public sealed class QueueInfo : ValueObject<QueueInfo>, IEquatable<QueueInfo>
    {
        public QueueInfo()
        {
        }

        public QueueInfo(string address)
        {
            Address = address;
        }

        public string Address { get; set; }
        public int MessagesCount { get; set; }
        public DateTime? OldestMessageTime { get; set; }

        public bool Equals(QueueInfo other)
        {
            if (ReferenceEquals(null, other))
            {
                return false;
            }
            if (ReferenceEquals(this, other))
            {
                return true;
            }
            return Equals(other.Address, Address);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }
            if (ReferenceEquals(this, obj))
            {
                return true;
            }
            if (obj.GetType() != typeof (QueueInfo))
            {
                return false;
            }
            return Equals((QueueInfo) obj);
        }

        public override int GetHashCode()
        {
            return (Address != null ? Address.GetHashCode() : 0);
        }

        public static bool operator ==(QueueInfo left, QueueInfo right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(QueueInfo left, QueueInfo right)
        {
            return !Equals(left, right);
        }
    }
}